import BaseApi from "@/api/BaseApi.ts";
import type IPageResp from "@/type/IPageResp.ts";
import type ISysDictReq from "../type/req/ISysDictReq.ts";
import type ISysDictResp from "../type/resp/ISysDictResp.ts";

class SysDictApi extends BaseApi {

    constructor() {
        super("/sys/dict")
    }

    /**
     * 分页查询
     */
    pageDict = (sysDictReq: ISysDictReq) => {
        return this.get<IPageResp<ISysDictResp>, ISysDictReq>('pageDict', sysDictReq)
    }

    /**
     * 根据id查询数据
     */
    queryById = (id: String) => {
        return this.get('queryById', {id})
    }

    /**
     * 根据有无id新增或编辑数据
     */
    saveOrUpdateDict = (sysDictReq: ISysDictReq) => {
        return this.post<string, ISysDictReq>('saveOrUpdateDict', sysDictReq)
    }

    /**
     * 根据id删除数据
     */
    deleteDict = (ids: string[]) => {
        return this.delete<string>('deleteDict', ids)
    }

    /** ==========================字典项============================================== */

    /**
     * 查询字典项
     */
    listDictItem = (sysDictReq: ISysDictReq) => {
        return this.get<ISysDictResp[], ISysDictReq>('listDictItem', sysDictReq)
    }

    /**
     * 新增编辑字典项
     */
    saveOrUpdateDictItem = (sysDictReq: ISysDictReq) => {
        return this.post<ISysDictResp[], ISysDictReq>('saveOrUpdateDictItem', sysDictReq)
    }

    /**
     * 根据id删除数据
     */
    deleteDictItem = (ids: string[]) => {
        return this.delete<string>('deleteDictItem', ids)
    }

}

export default new SysDictApi()